import requests
import time
from lxml import etree
import re
url='https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_600059_-_ctg1_600059'
headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
url='https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_600059_-_ctg1_600059'
response=requests.get(url=url,headers=headers)
time.sleep(2)
date=response.json()
datas=date['data']['statuses']
id_list=[]
for data in datas:
    my_id=data['id']
    id_list.append(my_id)
my_url=[]
for i in id_list:
    url_1=f'https://m.weibo.cn/status/{i}'
    my_url.append(url_1)
for url_2 in my_url:
    response=requests.get(url=url_2,headers=headers).text
    # texts=re.findall()
    text=re.findall('<span .*?>#(.*?)#</span></a>(.*?)<a .*>(.*?)</span>.*?</a>',response,re.S)
    print(text)


# parse=etree.HTML(data)
# weibo_tex1=parse.xpath('//div[@class="weibo-og"]')
# print(weibo_tex1)
# for i in weibo_tex1:
#     print(f"{i}"r'/''a')
# weibo_tex=parse.xpath('//div[@class="weibo-og"]')
# print(weibo_tex)



























#102803_ctg1_600059_-_ctg1_600059
#https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_600059_-_ctg1_600059
# url='https://m.weibo.cn/'
# headers = {
#         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
#     }
# response=requests.get(url=url,headers=headers)
# time.sleep(2)
# response.encoding=response.apparent_encoding
# date=response.text
# print(date)